	PROGRAM WHIZBANG

	implicit none

	integer aDefItem
	parameter ( aDefItem = Z'A8' )

	integer ctlprc , my_filter , filter_1 , my_filter_ptr
	external ctlprc , my_filter
	
	integer get_dit , result , dialog_ptr , toolbx
	
	integer top_field , bottom_field , result_field , end_dialog
	parameter ( top_field =		1 )
	parameter ( bottom_field =	2 )
	parameter ( result_field =	3 )
	parameter ( end_dialog =	4 )
	
	integer TEINIT
	parameter (TEINIT=Z'9CC00000')
	integer GETNEWDIALOG,DISPOSDIALOG,INITDIALOGS
	integer MODALDIALOG
	parameter (GETNEWDIALOG=Z'97C8A400',
     +	DISPOSDIALOG=Z'98310000',MODALDIALOG=Z'99116000')
	parameter (INITDIALOGS=Z'97B10000')
	INTEGER HIDEWINDOW
	PARAMETER (HIDEWINDOW=Z'91610000')
	INTEGER FRONTWINDOW
	PARAMETER (FRONTWINDOW=Z'92480000')
	
  	integer*2 ItemHit
	
	logical done

	filter_1 = ctlprc ( my_filter , 16 )	!Four long words 								!arguments
	call xfilt ( filter_1 , my_filter_ptr )
	
	done = .false.
	
	call toolbx (TEINIT)
	call toolbx ( INITDIALOGS , 0 )

	call toolbx ( HIDEWINDOW , toolbx ( FRONTWINDOW ) )

	dialog_ptr = toolbx ( GETNEWDIALOG , 100 , 0 , -1 )

	word ( dialog_ptr + aDefItem ) = 0
	
	do while ( .not. done )

	  call  toolbx ( MODALDIALOG , my_filter_ptr , ItemHit )
	  select case ( ItemHit )
	  
	    case ( top_field )
	      result = getdit ( top_field , dialog_ptr )
	      call setdit ( result , result_field , dialog_ptr )
	      

	    case ( bottom_field )
	      result = getdit ( bottom_field , dialog_ptr )
	      result = result * 10
	      call setdit ( result , result_field , dialog_ptr )
	      
	    case ( end_dialog )
	      call toolbx ( DISPOSDIALOG , dialog_ptr )
	      done = .true.

	    case default
	      continue

	  end select
	repeat

	end

	subroutine my_filter ( argptr )

	implicit none			! Declare all variables.

	integer toolbx
	integer Dg_ptr , ItemHit_ptr , ev_ptr , argptr , result_ptr
	
	integer i , char_code
	integer*2 ItemHit
	logical handle_event

	integer*1 eventrecord(16)	! overlying structure
	
	integer*2 what		! type of event:
	integer*4 when		! time of event in 60ths of seconds
	integer*2 where(2)	! mouse location in global coordinates
	integer*2 modifiers	! state of mouse button and modifier keys:
	integer*4 message		! extra event information:

     	equivalence ( eventrecord(1)  , what )
    	equivalence ( eventrecord(3)  , message )
    	equivalence ( eventrecord(7)  , when )
    	equivalence ( eventrecord(11) , where(1) )
    	equivalence ( eventrecord(15) , modifiers )

	integer aDefItem , editField
	parameter ( aDefItem = Z'A8', editField = Z'A4' )

	result_ptr = long ( argptr + 12 )
	Dg_ptr = long ( argptr + 8 )
	ev_ptr = long ( argptr + 4)
	ItemHit_ptr = long ( argptr )

	do ( i = 1 , 16 )
	  eventrecord (i)  = byte ( ev_ptr + i - 1 )
	repeat

    	if ( what .eq. 3 ) then		!key down

C  If user hits return or enter key, check the default item number. If 
C  it is zero, then return with ItemHit as the active edit text field. 
C  If the default item is nonzero, return it as the ItemHit.

    	  char_code = message .and. Z'000000FF'
    	  if ( char_code .eq. 13 .or. char_code .eq. 3 ) then
    	    if ( word ( Dg_ptr + aDefItem ) .eq. 0 ) then
    	      ItemHit = word ( Dg_ptr + editField ) + 1
    	      handle_event = .false.
    	    else
    	      ItemHit = word ( Dg_ptr + aDefItem )
    	      handle_event = .false.
    	    end if
    	  else
    	    handle_event = .true.
    	  end if
    	else
	  handle_event = .true.
	end if

	if ( handle_event ) then
    	  word ( result_ptr ) = z'0'
    	else
    	  word ( result_ptr ) = z'FFFF'
    	  word ( ItemHit_ptr ) = ItemHit
    	end if

	return
	end

	integer function get_dit ( item_num , dg_ptr )

	implicit none
	integer toolbx , item_num , dg_ptr ,itemhandle
	integer itemp , ktemp
	character*256 temp , dgtext
	integer*2 ItemType , box (4)

	integer GETDITEM , GETITEXT
	parameter (GETDITEM=Z'98D11DB0', GETITEXT=Z'99016000' )

	call toolbx ( GETDITEM , dg_ptr , item_num ,
     *	 	  ItemType , itemhandle , box )
	call toolbx ( GETITEXT , itemhandle , dgtext )
	itemp = ichar ( dgtext (1:1) ) + 1
	ktemp = 0
	if ( itemp .gt. 1 ) then
	  temp = dgtext ( 2 : itemp )
	  read ( temp , * , err = 100 ) ktemp
	end if
	get_dit = ktemp
	return
100	get_dit = 0

	return
	end

	subroutine set_dit ( value , item_num , dg_ptr )

	implicit none
	integer toolbx , item_num , dg_ptr , ItemType , itemhandle
	integer value
	integer*2 box (4)
	character*256 dgtext

	integer GETDITEM , SETITEXT
	parameter (GETDITEM=Z'98D11DB0', SETITEXT=Z'98F16000' )

	write ( dgtext , * ) value
	dgtext (1:1) = char ( len ( trim ( dgtext) ) - 1 )
	call toolbx ( GETDITEM , dg_ptr , item_num ,
     *	 	  ItemType , itemhandle , box )
	call toolbx ( SETITEXT , itemhandle , dgtext )

	return
	end

